# Create your views here.
from django import forms
from django.http import HttpResponse,HttpResponseRedirect
from django.shortcuts import render_to_response
from opadmin.models import Host


class UserForm(forms.Form):
    hostname = forms.CharField(max_length=100)
    ipaddr = forms.IPAddressField()
    program = forms.CharField(max_length=100,label='Your e-mail address')

    def clean_message(self):
        message = self.cleaned_data['hostname']
        num_words = len(message.split())
        if num_words < 4:
            raise forms.ValidationError("Not enough words!")
        return message

class AddProjectForm(forms.Form):
    name = forms.CharField(max_length=100)

def register(req):
    if req.method =='POST':
        uf = UserForm(req.POST)
        if uf.is_valid():
            hostname = uf.cleaned_data['hostname']
            ipaddr = uf.cleaned_data['ipaddr']
            program  = uf.cleaned_data['program']
            print hostname,ipaddr,program
#            User.objects.create(username=username,password=password)
            return HttpResponseRedirect('/login/')
    else :
        uf = UserForm()
    return render_to_response('register.html',{'uf':uf})

#def index(req):
#    return HttpResponse('<h1>hello</h1>')

def index(req):
    username = req.session.get('username','anybody')
    return render_to_response('index.html',{'username':username})

def get_server_list(list):
    pass

def add_project(req):
    if req.method =='POST':
        pf = AddProjectForm(req.POST)
        if pf.is_valid():
            name = pf.cleaned_data['name']
            print name
            Project.objects.create(name=name,)
#            User.objects.create(username=username,password=password)
            return HttpResponseRedirect('/login/')
    else :
        pf = AddProjectForm()
    return render_to_response('add_project.html',{'pf':pf})

def fabu(req):
    